package com.example.untils;

import com.example.entity.dto.User.MyUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 安全服务工具类
 *
 * @author ruoyi
 */
public class SecurityUtils {

    /**
     * 获取Authentication
     */
    public static Authentication getAuthentication()
    {
        return SecurityContextHolder.getContext().getAuthentication();
    }

    /**
     * 获取用户
     **/
    public static MyUser getLoginUser()
    {
        Object principal = getAuthentication().getPrincipal();
        if(principal instanceof MyUser) return (MyUser) getAuthentication().getPrincipal();
        else return null;
    }

}
